{% extends 'website/backend/backend_base.html' %}
{% block option-title %}
    修改文章分类
{% endblock %}

{% block content %}
    <div class="col-md-12">
        <form class="form-horizontal" id="data-form">
            <div class="form-group">
                <label for="name" class="col-sm-3 col-sm-offset-2 control-label">名称:</label>
                <div class="col-sm-3">
                    <input type="text" id="name" name="name" class="form-control" required value="{{ category.name }}">
                </div>
            </div>
            <button type="button" class="btn btn-info" id="submit-btn">修改</button>
            <input type="reset" name="reset" style="display: none">
        </form>
    </div>
    {% include 'utils/modal.html' %}
{% endblock %}
{% block js %}
    <script type="text/javascript">
        $('#submit-btn').click(function (e){
            e.preventDefault()
            var options = {
                type:"POST",
                dataType:'json',
                url:"{% url 'category-update' category.pk%}",
                success:function (data){
                    var state = data.state
                    if (state === 'success'){
                        showModal('success','修改成功')
                    }else {
                        showModal('danger','修改失败')
                    }
                    $('input[type=reset]').trigger('click')
                },
                error:function (data){
                    console.log(data)
                }
            }
            $('#data-form').ajaxSubmit(options)
        })
    </script>
{% endblock %}